# -*- coding: utf-8 -*-
# @Time:2021/04/27 21:49
# @Author:Cindy
from appium import webdriver
from pages.base_page import BasePage
from pages.main_page import MainPage


class App(BasePage):

    def start(self):
        if self.driver is None:
            # 启动app
            caps = {
                "platformName": "android",
                "deviceName": "hongwarts",
                "appPackage": "com.tencent.wework",
                "appActivity": ".launch.WwMainActivity",
                "settings[waitForIdleTimeout]": 0,
                "noReset": "true"
            }
            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
            self.driver.implicitly_wait(10)
        else:
            # 复用driver，启动app
            self.driver.launch_app()
        return self

    def stop(self):
        # 退出app
        self.driver.quit()

    def restart(self):
        # 关闭app
        self.driver.close_app()
        # 重新打开app
        self.driver.launch_app()

    def goto_main_page(self):
        # 入口，进入企业微信主页面
        return MainPage(self.driver)
